1 00:00:00,710 --> 00:00:01,400 Okay. 2 00:00:01,400 --> 00:00:04,040 We're getting pretty close to the end of our project. 3 00:00:04,040 --> 00:00:08,300 So in this lecture we're going to finish up scripting the story for our basement, where we're going 4 00:00:08,300 --> 00:00:13,250 to listen for when the basement door is opened and when it is, we'll enable a prompt on the breaker 5 00:00:13,250 --> 00:00:14,900 and wait for that prompt to get triggered. 6 00:00:14,900 --> 00:00:19,340 Once that prompt is triggered, we'll restore the power in the basement and then start a countdown of 7 00:00:19,340 --> 00:00:23,090 around 60s for the players to reach the exit door in the basement. 8 00:00:23,630 --> 00:00:29,120 So after we have finished with our stair scene, the next thing we'll want to do is we're going to listen 9 00:00:29,120 --> 00:00:30,620 inside of the workspace. 10 00:00:30,620 --> 00:00:35,510 Inside of the Krusty Krab, we're going to look in the doors folder and get our locked door, and we're 11 00:00:35,510 --> 00:00:40,850 going to get an attribute change signal, and we're going to wait for the locked attribute to change, 12 00:00:40,850 --> 00:00:44,450 because this will change when that door gets unlocked. 13 00:00:44,450 --> 00:00:46,760 So we're going to wait for this to happen. 14 00:00:46,760 --> 00:00:51,800 So this will notify us when the players have gotten the key and then opened and unlocked the basement 15 00:00:51,800 --> 00:00:52,820 breaker room door. 16 00:00:53,290 --> 00:00:56,080 Once that happens, then we're going to reference in the workspace. 17 00:00:56,230 --> 00:00:58,090 Krusty Krab basement. 18 00:00:58,090 --> 00:01:03,190 We're going to get the breaker box, and inside of the body of the breaker box, there's an attachment 19 00:01:03,190 --> 00:01:08,110 with our proximity prompt inside of it, and we're going to want to enable this prompt. 20 00:01:08,110 --> 00:01:10,300 That way the players can activate it. 21 00:01:10,300 --> 00:01:12,580 And then we're just going to copy this. 22 00:01:12,580 --> 00:01:15,340 And we're going to wait for this prompt to get triggered. 23 00:01:15,340 --> 00:01:20,050 Once this prompt is triggered, then we need to go ahead and restore the power in the basement so we 24 00:01:20,050 --> 00:01:22,270 can go ahead and create a private function. 25 00:01:22,270 --> 00:01:25,660 And I'm just going to call this function Restore power. 26 00:01:26,710 --> 00:01:30,610 And what we're going to do is we're just going to call our change light's function and pass true. 27 00:01:30,610 --> 00:01:33,400 And then we also need to play a sound as well. 28 00:01:33,400 --> 00:01:39,280 So we're going to use the game comms event and fire to all the clients and use the game comms enum on 29 00:01:39,280 --> 00:01:40,120 the client. 30 00:01:40,120 --> 00:01:47,410 And two clients play sound, and the sound is going to be inside of the sound service ambience dot. 31 00:01:47,410 --> 00:01:48,880 And it's called restored. 32 00:01:48,880 --> 00:01:52,780 And we're going to set play at point equal to false. 33 00:01:53,110 --> 00:01:57,940 So if I go down into the sound service we go into the ambience folder. 34 00:01:57,940 --> 00:01:59,320 Here's the restored sound. 35 00:01:59,320 --> 00:02:01,930 This is what we're going to play when we turn back on the power. 36 00:02:06,910 --> 00:02:07,870 Pretty simple. 37 00:02:08,820 --> 00:02:13,350 Once we have restored the power, the next thing we'll want to do is we're going to want to open the 38 00:02:13,350 --> 00:02:15,780 door that leads to the exit inside of our basement. 39 00:02:15,780 --> 00:02:21,300 So if we go all the way back here, this is the door right here that we're going to open to allow the 40 00:02:21,300 --> 00:02:23,700 players to touch this escape part. 41 00:02:23,700 --> 00:02:26,850 And we're also going to change this light up here to green. 42 00:02:26,850 --> 00:02:32,400 So that means we're going to have to tween this door slowly open so we can go ahead and create a function. 43 00:02:32,400 --> 00:02:36,840 And I'll just call this function something like enable exit door. 44 00:02:37,810 --> 00:02:43,600 And we'll make a reference to the exit door inside of the workspace Krusty Krab basement and get the 45 00:02:43,600 --> 00:02:44,410 exit door. 46 00:02:45,630 --> 00:02:51,780 We're also going to refer to the escape part, which is in the workspace Krusty Krab basement escape 47 00:02:51,780 --> 00:02:52,170 part. 48 00:02:52,170 --> 00:02:55,650 And then we're going to make a reference to the light that's above the door as well. 49 00:02:55,650 --> 00:03:02,100 We'll call it Escape Light, and that's in the workspace Krusty Krab basement exit door light. 50 00:03:03,160 --> 00:03:07,420 And then from this point, inside of the escape part, we have a surface light in there, and we're 51 00:03:07,420 --> 00:03:09,670 going to enable that surface light. 52 00:03:09,670 --> 00:03:11,470 And I'll go ahead and show you what that does. 53 00:03:11,470 --> 00:03:15,790 So when we rotate this door open, let me just change the rotation of the hinge here. 54 00:03:15,790 --> 00:03:17,740 And we could do something like. 55 00:03:19,300 --> 00:03:20,440 We'll just do that for now. 56 00:03:20,470 --> 00:03:24,100 When the store opens, we want to have light glowing out and hitting this wall. 57 00:03:24,100 --> 00:03:26,230 So inside of the escape part, there's a surface light. 58 00:03:26,230 --> 00:03:30,730 And when we enable that, it's going to have this bright glowing light coming out of this doorway, 59 00:03:30,730 --> 00:03:31,990 which looks kind of cool. 60 00:03:34,080 --> 00:03:37,950 So let me go ahead and place this hinge back to its regular state. 61 00:03:40,340 --> 00:03:46,250 So once we've enabled the surface light, then we're going to want to change the color of the bulb in 62 00:03:46,250 --> 00:03:47,720 our escape light. 63 00:03:47,720 --> 00:03:52,340 So escape light bulb, we want to set the color to be green. 64 00:03:52,340 --> 00:03:54,860 So we could define a constant up here. 65 00:03:55,220 --> 00:03:57,590 We'll just call this constant green. 66 00:03:57,590 --> 00:04:00,560 And we'll make it equal to a color three dot from RGB. 67 00:04:00,650 --> 00:04:04,370 And we'll just pass in some random green color like that. 68 00:04:04,850 --> 00:04:08,540 We'll go back down and we'll set this equal to the green color. 69 00:04:09,590 --> 00:04:13,490 And then we're also going to change the point light inside of the bulb as well. 70 00:04:13,490 --> 00:04:17,660 So the light bulb will get the point light in there. 71 00:04:17,660 --> 00:04:20,780 And we'll change the color of that as well equal to the green color. 72 00:04:21,770 --> 00:04:26,090 And now we're going to use the game comms event and fire to all of the clients to play another sound. 73 00:04:26,090 --> 00:04:30,410 So game comms enum client two client play sound. 74 00:04:30,530 --> 00:04:36,380 And the sound that we want for them to play is going to be inside of our exit door. 75 00:04:36,410 --> 00:04:40,160 We get the door and then there's a sound in there called alarm. 76 00:04:40,740 --> 00:04:44,070 We're going to set play at point equal to true. 77 00:04:44,400 --> 00:04:50,700 And the position for that is going to be equal to our exit door dot door dot position. 78 00:04:50,850 --> 00:04:55,920 After that, we can go ahead and use the better tween service to go ahead and rotate the door so we 79 00:04:55,920 --> 00:04:59,730 can go ahead and require it at the top here we'll get the better tween. 80 00:05:01,180 --> 00:05:08,170 And will require inside of the server script service, dot server, dot modules, dot beta tween. 81 00:05:08,710 --> 00:05:16,330 And then we can go back down and use the beta tween service and create a tween on our exit door hinge. 82 00:05:16,510 --> 00:05:20,230 We'll do a tween info dot new and we can slowly open it. 83 00:05:20,230 --> 00:05:26,710 So we could do like five seconds and then do an enum dot easing style of uh, we'll do linear and we're 84 00:05:26,710 --> 00:05:34,390 going to want to change the key frame of this door equal to the exit door dot hinge dot c frame. 85 00:05:34,510 --> 00:05:37,510 And we'll add a C frame angles. 86 00:05:37,510 --> 00:05:39,490 We'll do zero on the x axis. 87 00:05:39,490 --> 00:05:45,190 And then for the y axis we're going to do math dot rad and rotate it by around -110 degrees and then 88 00:05:45,190 --> 00:05:47,200 zero on the z axis. 89 00:05:47,200 --> 00:05:49,150 And that's all we need to do for this function. 90 00:05:49,150 --> 00:05:53,320 So we can go back down into our start section two function. 91 00:05:53,320 --> 00:05:58,510 We'll want to restore the power and then we'll want to enable our exit door. 92 00:05:58,720 --> 00:06:03,070 From this point we can use our update GUI event and fire to all of the clients that they fulfilled, 93 00:06:03,070 --> 00:06:05,440 an objective which was to restore the power. 94 00:06:05,440 --> 00:06:13,900 So GUI actions enum dot objective fulfilled and then the fulfilled objective name is equal to restore 95 00:06:13,900 --> 00:06:14,530 power. 96 00:06:15,360 --> 00:06:20,070 And then we can use the update UI again and give them all a new objective. 97 00:06:20,070 --> 00:06:25,800 So GUI actions, Nomad objective, and the name we could set for this objective would be like escape. 98 00:06:25,800 --> 00:06:29,670 So we can go back up and create a new objective. 99 00:06:30,510 --> 00:06:31,920 Call it escape. 100 00:06:34,110 --> 00:06:37,980 And the text will set in here would be something like escape the basement. 101 00:06:39,370 --> 00:06:44,410 We'll go back down, we'll give them this objective and then we'll give them the text which is in game 102 00:06:44,410 --> 00:06:49,840 sections dot objectives, dot escape and then get the text. 103 00:06:50,740 --> 00:06:55,450 After that, we're going to wait like one second, and then we're going to use the game comms event 104 00:06:55,450 --> 00:07:00,820 and fire to all the clients to begin playing the sound or music that will play when they're trying to 105 00:07:00,820 --> 00:07:01,240 escape. 106 00:07:01,240 --> 00:07:08,140 So game comms enum on the client two client play sound and the sound is inside of the sound service. 107 00:07:08,140 --> 00:07:12,760 Don ambience dot escape music and then play at point. 108 00:07:14,140 --> 00:07:15,640 It's going to be equal to false. 109 00:07:16,330 --> 00:07:20,800 So when it is time to escape the basement, we're going to be playing this. 110 00:07:24,460 --> 00:07:26,200 Pretty basic and nice music. 111 00:07:26,590 --> 00:07:30,670 And that's all we need to do for our start section to function. 112 00:07:30,670 --> 00:07:31,720 It is over. 113 00:07:31,900 --> 00:07:37,180 That means when we go back to our game service, where our start section two function was called, which 114 00:07:37,180 --> 00:07:42,610 was right here, we can then go ahead and start executing functionality outside of it once we return 115 00:07:42,610 --> 00:07:43,690 out of the function. 116 00:07:43,930 --> 00:07:47,140 So now what we could do is we could create a new variable. 117 00:07:47,140 --> 00:07:50,950 And we're going to call this ready for escape part. 118 00:07:51,070 --> 00:07:52,990 By default we're going to set this to false. 119 00:07:52,990 --> 00:07:58,540 And then we can scroll back down and set ready for escape part equal to true. 120 00:07:59,050 --> 00:08:04,600 And what we're going to do is we're going to create a for loop starting at the index of 60, going all 121 00:08:04,600 --> 00:08:08,620 the way down to I guess we'll do zero minus one each time. 122 00:08:08,620 --> 00:08:12,970 And this is the loop we're going to do to give them a countdown to escape the basement. 123 00:08:13,090 --> 00:08:19,600 So we'll use our update UI event and fire to all of the clients to do a GUI actions enum dot update 124 00:08:19,600 --> 00:08:20,680 countdown. 125 00:08:20,950 --> 00:08:23,890 And the number is going to be equal to the current index. 126 00:08:23,890 --> 00:08:27,910 So this is going to be the timer for all the players to escape the basement. 127 00:08:27,910 --> 00:08:34,480 And then once this loop is over, then we can have a function to teleport all of our players back to 128 00:08:34,480 --> 00:08:39,790 the lobby or teleport the losing players back to the lobby, because when our winning players touch, 129 00:08:39,790 --> 00:08:44,920 the part will automatically teleport them back, but any players that are left over or the losing players 130 00:08:44,920 --> 00:08:47,530 will need to teleport them back to the lobby as well. 131 00:08:47,890 --> 00:08:52,360 So we can scroll up and go ahead and create a private function, and we can call this function something 132 00:08:52,360 --> 00:08:53,260 like teleport. 133 00:08:53,260 --> 00:08:55,720 Losing players to lobby. 134 00:08:56,500 --> 00:09:00,670 And what we would do is we would loop through every single player inside of the player service. 135 00:09:00,670 --> 00:09:03,460 So whatever players are remaining inside of our game. 136 00:09:06,540 --> 00:09:12,570 What we're going to do is we're going to ensure that they aren't an escaped players because we're going 137 00:09:12,570 --> 00:09:15,030 to be doing something for the escape players. 138 00:09:15,030 --> 00:09:21,480 So we'll have to create a table that keeps track of all the escaped players. 139 00:09:22,200 --> 00:09:25,140 And inside of here we'll just insert the name of the player. 140 00:09:25,140 --> 00:09:26,010 So. 141 00:09:26,670 --> 00:09:27,600 Inside of our function. 142 00:09:27,600 --> 00:09:32,730 We can check if inside of the escape players table this player is inside of it. 143 00:09:32,730 --> 00:09:34,680 If they are an escape player. 144 00:09:34,680 --> 00:09:36,840 If they are, then we're just going to continue looping. 145 00:09:37,260 --> 00:09:43,170 Otherwise, what we could do is we could use our update UI event and fire to this particular player 146 00:09:43,170 --> 00:09:46,440 and give them the action enum of outro frame. 147 00:09:46,440 --> 00:09:50,100 So this is something we're going to have to fill out in our main UI handler. 148 00:09:50,550 --> 00:09:55,350 And this means we're also going to have to give them a table containing a bunch of different data to 149 00:09:55,350 --> 00:09:57,240 display on our outro frame. 150 00:09:57,880 --> 00:10:02,950 So inside of our main guy handler on the client, when we are told to display an outro frame, what 151 00:10:02,950 --> 00:10:07,150 we're going to do is we're going to get our outro frame and set the visibility equal to true. 152 00:10:07,600 --> 00:10:11,140 And inside of this args table, we can have a bunch of different text passed to us. 153 00:10:11,140 --> 00:10:17,050 So for example, inside of the outer frame.info label, we can set the text equal to whatever text is 154 00:10:17,050 --> 00:10:18,190 passed from the server. 155 00:10:18,190 --> 00:10:21,760 So we can have a key in there called like info text. 156 00:10:21,760 --> 00:10:26,980 And then in the outro frame dot title label, we could add some text from the server as well. 157 00:10:26,980 --> 00:10:29,500 So we could do args dot title text. 158 00:10:30,040 --> 00:10:36,790 And then what we could also get passed to this function is the completed tasks that you know the player 159 00:10:36,790 --> 00:10:37,420 finished. 160 00:10:37,420 --> 00:10:45,970 So we could loop through every single, uh, task inside of a table like args dot completed tasks. 161 00:10:45,970 --> 00:10:50,230 Because you remember inside of our tasks service, it can return back to us a table with a bunch of 162 00:10:50,230 --> 00:10:56,500 different key value pairs, numbering the different tasks we completed so we could get that number value 163 00:10:56,500 --> 00:10:57,820 and add it to a total. 164 00:10:57,820 --> 00:11:00,850 So we could have a total here start at zero. 165 00:11:01,730 --> 00:11:04,550 And then we will just add this number to the total. 166 00:11:06,520 --> 00:11:12,460 And after we do that, inside of the outro frame, we have a stats label and we can set the text in 167 00:11:12,460 --> 00:11:17,260 that equal to something like, we'll put a string here and we could say you had. 168 00:11:17,290 --> 00:11:20,680 We'll put a directive percentage de dollars. 169 00:11:21,500 --> 00:11:28,850 And percentage the tasks completed, so it'll tell us how much money we earned and how much tasks we 170 00:11:28,850 --> 00:11:29,540 completed. 171 00:11:29,540 --> 00:11:33,140 And then we can go ahead and format the string and pass the args. 172 00:11:33,140 --> 00:11:35,240 And we could get like the amount of money we had. 173 00:11:35,240 --> 00:11:36,440 So args dot money. 174 00:11:36,440 --> 00:11:40,580 And then we could also pass the total number here of tasks we completed. 175 00:11:41,120 --> 00:11:47,570 And then once we do that, our outer frame is still going to be invisible because it's currently transparent. 176 00:11:47,570 --> 00:11:52,970 So we need to fade it in and we can use the fade element function, pass our outer frame. 177 00:11:53,390 --> 00:11:56,540 And we're going to set the duration to one second. 178 00:11:56,540 --> 00:11:58,640 And we want to fade it to be completely opaque. 179 00:11:59,060 --> 00:12:03,740 And that means we're also going to have to fade in all of the different text labels inside of the outer 180 00:12:03,740 --> 00:12:04,070 frame. 181 00:12:04,070 --> 00:12:08,300 So we would get every single child inside of our outer frame, get children. 182 00:12:09,870 --> 00:12:14,040 And we would fade the element of this particular child. 183 00:12:14,830 --> 00:12:18,550 We'll do the same duration of one second and then zero for the transparency. 184 00:12:19,000 --> 00:12:21,850 Now the problem is that this function if you remember, yields. 185 00:12:21,850 --> 00:12:24,490 So instead we're going to have to spawn it in a new thread. 186 00:12:24,490 --> 00:12:26,410 So task dot spawn this function. 187 00:12:28,550 --> 00:12:31,730 And then we'll just pass all the other stuff along with it. 188 00:12:34,110 --> 00:12:39,360 And then we can just basically copy this, do the same thing here, but instead we're passing the child 189 00:12:39,360 --> 00:12:41,370 that is inside of our outro frame. 190 00:12:41,460 --> 00:12:44,580 So this will fade all of the outro stuff onto our screen. 191 00:12:44,580 --> 00:12:49,350 And then from this point, there's also a section in our outro frame where we'll have a section that 192 00:12:49,350 --> 00:12:54,990 says teleporting you back to the lobby, and we'll do like teleporting back to lobby. 193 00:12:54,990 --> 00:12:57,810 And then we could do dot dot, dot like a loading bar. 194 00:12:57,810 --> 00:13:00,270 So we'll create a message here. 195 00:13:00,270 --> 00:13:01,470 We'll just call it. 196 00:13:03,200 --> 00:13:06,500 Teleporting you back to lobby. 197 00:13:07,870 --> 00:13:13,000 And then inside of the outer frame dot loading text or I believe it's loading label. 198 00:13:13,000 --> 00:13:15,430 We'll get the text in there and set it equal to this message. 199 00:13:16,640 --> 00:13:19,370 We'll wait like point five seconds. 200 00:13:19,370 --> 00:13:23,540 And then once we do that, we're going to have a loop that runs forever. 201 00:13:23,540 --> 00:13:29,000 And what we're going to do is we're going to check if the outer frame dot loading label dot text is 202 00:13:29,000 --> 00:13:31,580 equal to the message and concatenate it with the three dots. 203 00:13:31,580 --> 00:13:35,150 And when it is, that means we're going to have to reset it back to the message. 204 00:13:35,600 --> 00:13:40,040 So outro frame dot loading label dot text is equal to the message. 205 00:13:40,640 --> 00:13:43,460 And then we can yield for something like 0.5 seconds. 206 00:13:43,460 --> 00:13:44,600 And then after that. 207 00:13:45,240 --> 00:13:49,890 We'll refer to the outer frame loading label dot text. 208 00:13:49,890 --> 00:13:52,020 Set it equal to itself. 209 00:13:53,010 --> 00:13:55,620 And then just concatenate it with a period. 210 00:13:55,620 --> 00:13:57,750 And again we'll yield for 0.5 seconds. 211 00:13:57,750 --> 00:13:59,160 So this loop will run forever. 212 00:13:59,160 --> 00:14:01,800 Just filling out that loading bar for us. 213 00:14:03,010 --> 00:14:07,870 So back inside of our game service, the things that we're going to have to pass here, first of all, 214 00:14:08,290 --> 00:14:11,650 we're giving them the action of the outer frame and then inside of the table. 215 00:14:11,650 --> 00:14:14,650 What we can pass in here is first the money that the player earns. 216 00:14:14,650 --> 00:14:19,060 So that's going to be in the player's leader stats folder and get their money. 217 00:14:19,060 --> 00:14:20,860 And then get the value of that money. 218 00:14:21,070 --> 00:14:25,210 We could set the title text equal to something like you failed. 219 00:14:26,090 --> 00:14:30,860 We'll set the info text equal to something like. 220 00:14:30,860 --> 00:14:39,440 Unfortunately, you fail to win this time and we just give some encouraging words don't give up, try 221 00:14:39,440 --> 00:14:40,220 again. 222 00:14:40,220 --> 00:14:41,480 Something like that. 223 00:14:41,900 --> 00:14:48,770 And we're also going to have to pass all of the completed tasks that this player, you know did. 224 00:14:48,770 --> 00:14:53,630 So that means if you remember if we go back to our task service. 225 00:14:54,230 --> 00:14:58,190 When our Bindable function is used. 226 00:14:58,190 --> 00:15:00,890 If we scroll down here, we have our. 227 00:15:02,020 --> 00:15:02,890 Where is it? 228 00:15:02,920 --> 00:15:03,610 Task service. 229 00:15:03,610 --> 00:15:04,840 The task service Bindable. 230 00:15:04,840 --> 00:15:09,880 When that is invoked, we return back from this function, which gives us a table containing all of 231 00:15:09,880 --> 00:15:11,200 the completed tasks. 232 00:15:11,200 --> 00:15:16,870 So that means inside of our game service, we're going to have to make a reference to that remote function. 233 00:15:17,020 --> 00:15:18,640 So we can scroll up. 234 00:15:18,640 --> 00:15:20,740 We can have a section up here. 235 00:15:20,740 --> 00:15:24,130 We'll call it Task Service Bindable. 236 00:15:24,130 --> 00:15:27,340 And that's in the server storage dot events dot Bindesboll's. 237 00:15:27,340 --> 00:15:28,930 Dot task service Bindable. 238 00:15:29,940 --> 00:15:34,380 And that means we're also going to have to get the game comms enum for the server. 239 00:15:34,380 --> 00:15:42,090 So we'll require from server script service, dot server, dot modules, dot enums, dot game communication 240 00:15:42,090 --> 00:15:42,690 enum. 241 00:15:43,170 --> 00:15:45,150 And then we can go back down. 242 00:15:45,150 --> 00:15:52,920 And what we'll do is we'll create another key inside of here which represents the completed tasks. 243 00:15:55,000 --> 00:15:58,090 And that's going to be equal to our task service buildable. 244 00:15:58,090 --> 00:16:06,280 And we're going to invoke and pass the action using the uh, game comms enum for the server dot task 245 00:16:06,280 --> 00:16:06,730 service. 246 00:16:06,730 --> 00:16:09,910 And we're going to get completed tasks for player. 247 00:16:10,700 --> 00:16:15,770 And if you remember, the player we need to pass here is going to be the player inside of this for loop. 248 00:16:15,770 --> 00:16:18,170 So we'll just put the player inside of this table. 249 00:16:19,190 --> 00:16:21,260 And we should be good to go there. 250 00:16:21,260 --> 00:16:26,000 So once we do that for all the players, we're going to wait a random amount of time. 251 00:16:26,000 --> 00:16:27,410 We could do like 10s. 252 00:16:27,410 --> 00:16:31,040 That way we just have enough time for the players to read what's on their screen. 253 00:16:31,040 --> 00:16:36,260 So we'll wait 10s and after those 10s, then we're just going to teleport every single player inside 254 00:16:36,260 --> 00:16:38,780 of the game back to the lobby. 255 00:16:38,780 --> 00:16:42,440 And that means we're going to have to use our teleport handler for doing this. 256 00:16:42,440 --> 00:16:48,140 So let's go ahead and fill this service out in here, the only service we'll need is the teleport service. 257 00:16:48,140 --> 00:16:51,110 We use game get service teleport service. 258 00:16:51,890 --> 00:16:54,620 We'll create the table to represent this handler. 259 00:16:54,620 --> 00:16:58,550 So teleport handler is equal to a table. 260 00:16:58,550 --> 00:17:01,310 Return that at the end of this module script. 261 00:17:01,810 --> 00:17:07,540 And then we're also going to make a reference to the place id enum, which is going to store all the 262 00:17:07,540 --> 00:17:09,130 different place IDs. 263 00:17:09,130 --> 00:17:13,960 So we'll require inside of the script the child is the place id enum. 264 00:17:14,260 --> 00:17:17,620 And to fill this out we'll just grab one of these random enums like this one. 265 00:17:17,620 --> 00:17:21,250 I'll copy all this, paste it inside of the place id enum. 266 00:17:21,250 --> 00:17:23,590 But instead we want to delete this. 267 00:17:23,740 --> 00:17:30,250 And we're going to want to make a key for our lobby or the ID to teleport the players back to the lobby. 268 00:17:30,250 --> 00:17:33,130 So we can call this lobby, and we'll set it equal to a number. 269 00:17:33,130 --> 00:17:37,540 And now to get the ID for our lobby, we can go to the view tab and open up our asset manager. 270 00:17:37,540 --> 00:17:39,460 We can go to places in our game. 271 00:17:39,460 --> 00:17:42,910 And then here is our lobby the horror game. 272 00:17:42,910 --> 00:17:47,140 We can go copy the ID to clipboard and then store it inside of our table. 273 00:17:47,760 --> 00:17:53,160 So back inside our place id enum, what we can do is we can have a function in here. 274 00:17:53,520 --> 00:17:57,900 So teleport handler we can call it teleport player two. 275 00:17:58,810 --> 00:18:04,630 And what this function will get past is a table containing all the players we wish to teleport, so 276 00:18:04,630 --> 00:18:11,830 we can call it players, and this will be a table containing elements of the player data type. 277 00:18:12,160 --> 00:18:15,550 And then we'll also get the ID that we want to teleport to. 278 00:18:17,110 --> 00:18:22,390 Now, of course, just in case you know, a developer makes an error, we want to ensure that this place 279 00:18:22,390 --> 00:18:25,510 ID actually exists within our place id enum. 280 00:18:25,510 --> 00:18:27,520 So we could create a function to check that. 281 00:18:27,520 --> 00:18:30,640 We could call it is id in enum. 282 00:18:30,640 --> 00:18:36,700 And we would get passed an ID and all we'll do is we'll have a variable, we'll call it result, set 283 00:18:36,700 --> 00:18:37,780 it to false by default. 284 00:18:37,780 --> 00:18:44,290 And we're going to loop through every single enum and then value inside of our place id enum. 285 00:18:44,890 --> 00:18:48,040 And we're going to check if the value is equal to this ID. 286 00:18:48,040 --> 00:18:50,530 If it is, then we can set result equal to true. 287 00:18:50,530 --> 00:18:54,910 Otherwise we're just going to return result which will either be true or false. 288 00:18:55,570 --> 00:19:00,280 So we can check if this place ID passed to this function is not in this enum, and if it isn't, then 289 00:19:00,280 --> 00:19:03,340 we're going to put out a warning message in the console. 290 00:19:03,340 --> 00:19:07,600 So if not is id and enum, we'll pass the place ID. 291 00:19:08,260 --> 00:19:13,000 If it's not in there, then we're going to put out a Warn statement and say something like incorrect 292 00:19:13,000 --> 00:19:21,040 place ID given to teleport player to function, and then we can go ahead and return. 293 00:19:21,400 --> 00:19:26,620 Otherwise the next thing we can do is we can use our teleport async function in the teleport service. 294 00:19:26,620 --> 00:19:28,450 And we're going to use a p call on it. 295 00:19:28,450 --> 00:19:32,380 So we'll get the success and the result from p call. 296 00:19:32,380 --> 00:19:37,870 And the function we're going to p call is the teleport service dot teleport async. 297 00:19:39,510 --> 00:19:47,100 Since this function uses a colon, that means we have to pass the teleport service itself as the first 298 00:19:47,100 --> 00:19:51,990 argument, and then the second argument needs to be the id, which will pass as the place id. 299 00:19:52,020 --> 00:19:57,240 And then the second argument needs to be the table containing all the players we wish to teleport, 300 00:19:57,240 --> 00:19:59,880 which will be the players passed to this function. 301 00:20:00,940 --> 00:20:05,530 If we were not successful in teleporting the players, then what we're going to do is we're going to 302 00:20:05,530 --> 00:20:10,750 loop through every single player inside of our players table, and we're just going to kick them. 303 00:20:10,750 --> 00:20:12,640 So player kick. 304 00:20:13,410 --> 00:20:17,070 And we can give them a message like an error occurred. 305 00:20:17,920 --> 00:20:25,510 When trying to teleport you back to the lobby, and we can go ahead and give them the error message 306 00:20:25,510 --> 00:20:28,390 as well, using a directive. 307 00:20:28,420 --> 00:20:34,570 And then we can go ahead and wrap this string in another set of parentheses, and then format this and 308 00:20:34,570 --> 00:20:36,550 pass the result from our p call. 309 00:20:37,210 --> 00:20:40,960 And then once that's done, we can just go ahead and return out of the function. 310 00:20:41,290 --> 00:20:46,090 Otherwise, if we were successful in teleporting these players back to the lobby. 311 00:20:46,650 --> 00:20:50,610 Then we're going to spawn a task delay function. 312 00:20:50,610 --> 00:20:52,260 We'll wait 15 seconds. 313 00:20:52,890 --> 00:20:57,600 And after that, any other player that is still somehow sitting in our game that was inside of this 314 00:20:57,600 --> 00:21:01,320 player service, we're going to kick because somehow their teleport timed out. 315 00:21:01,320 --> 00:21:08,040 So for every single player and players, what we'll do is we'll kick them and give them a message of 316 00:21:08,040 --> 00:21:11,190 like teleport timed out, perfect. 317 00:21:11,190 --> 00:21:15,630 And that's all we got to do for our teleport handler and our place ID enum, so we can go ahead and 318 00:21:15,630 --> 00:21:16,920 close out of those. 319 00:21:17,950 --> 00:21:22,660 And now back inside of the game service to teleport the losing players back to the lobby. 320 00:21:22,660 --> 00:21:27,550 We're going to use our teleport handler, so we'll have to make a variable to it. 321 00:21:27,550 --> 00:21:36,640 So up here we could have our teleport handler and we'll require it from service script service dot server, 322 00:21:36,640 --> 00:21:38,530 dot modules dot teleport handler. 323 00:21:38,530 --> 00:21:40,210 And then we'll also get the enum as well. 324 00:21:40,210 --> 00:21:45,280 So place id enum will require from server script service. 325 00:21:45,990 --> 00:21:54,480 That server dot modules, dot teleport handler, dot place id enum and then we can go back down. 326 00:21:54,660 --> 00:21:57,720 Use our teleport handler and teleport player two. 327 00:21:57,750 --> 00:22:03,750 We'll pass our player, so we'll use the player service and get all the players that are in the game. 328 00:22:04,050 --> 00:22:08,430 And then the ID we're going to use is in the place id enum and pass the lobby. 329 00:22:08,430 --> 00:22:09,300 Perfect. 330 00:22:09,540 --> 00:22:14,730 So now we can go ahead and scroll back down, and we can go ahead and call this function after our for 331 00:22:14,730 --> 00:22:15,420 loop has ended. 332 00:22:15,420 --> 00:22:18,660 So we could call teleport losing players to lobby. 333 00:22:18,660 --> 00:22:22,980 And now the next thing we can fill out is when our escape part gets touched. 334 00:22:22,980 --> 00:22:26,220 So the first thing we want to check is if we're ready for this touch part. 335 00:22:26,220 --> 00:22:32,190 So if not ready for our escape part, then we're just going to return. 336 00:22:32,730 --> 00:22:37,860 If whatever touch this was not part of a character, so if not other part. 337 00:22:38,590 --> 00:22:44,440 Dot parent find first child or which is a. 338 00:22:45,150 --> 00:22:50,550 Humanoid, then we're going to go ahead and return, and we're going to have to get this other part. 339 00:22:51,690 --> 00:22:56,790 We need to check if a player touched this so we can get the player from the player service players get 340 00:22:56,790 --> 00:22:58,110 player from character. 341 00:22:58,110 --> 00:22:59,220 Pass other parts. 342 00:22:59,220 --> 00:23:00,000 Parent. 343 00:23:01,690 --> 00:23:06,520 If there is no player, then we're just going to return and the next thing we need to check is if this 344 00:23:06,520 --> 00:23:08,320 player already escaped. 345 00:23:08,320 --> 00:23:13,810 So if inside of the escape players table, this player's name already has a key in there, then we're 346 00:23:13,810 --> 00:23:15,040 just going to return. 347 00:23:15,130 --> 00:23:19,990 Otherwise, inside of the escape players table, we can create a new key for this player player name. 348 00:23:19,990 --> 00:23:21,760 And we'll just set it to something like true. 349 00:23:22,150 --> 00:23:27,190 And then we can set an attribute on this player of escaped equal to true. 350 00:23:27,190 --> 00:23:32,860 That way our AI doesn't try to target this player because they've escaped. 351 00:23:32,980 --> 00:23:40,360 We're going to use the update UI event and fire to this particular player GUI actions enum dot objective 352 00:23:40,360 --> 00:23:47,950 fulfilled and that is going to be the fulfilled objective name which is equal to escape. 353 00:23:48,960 --> 00:23:49,440 From here. 354 00:23:49,440 --> 00:23:52,980 We're also going to go ahead and get the completed tasks for this player. 355 00:23:52,980 --> 00:23:58,890 So that means we'll get the result from our task service by double. 356 00:23:59,470 --> 00:24:07,750 And we're going to invoke game comms, enum server, dot test service dot get completed tasks for player, 357 00:24:07,750 --> 00:24:11,710 and the player is going to be the one inside of this function. 358 00:24:12,640 --> 00:24:18,010 And actually I do remember that this invoke function returns two arguments. 359 00:24:18,010 --> 00:24:20,950 One is a boolean and then the other is our result. 360 00:24:20,950 --> 00:24:28,540 So that means back when we teleport the losing players to the lobby, we should actually get our tasks 361 00:24:28,540 --> 00:24:29,860 outside of this. 362 00:24:29,860 --> 00:24:31,990 So we'll copy this here. 363 00:24:36,160 --> 00:24:42,550 Paste that here so we could call this, uh, we'll just call it completed tasks, and then we can pass 364 00:24:42,550 --> 00:24:44,860 the completed tasks to this section right here. 365 00:24:44,860 --> 00:24:49,150 Otherwise, this would be storing a boolean rather than the completed tasks. 366 00:24:50,170 --> 00:24:52,900 And we'll make sure to close this out as well. 367 00:24:57,150 --> 00:24:58,530 And then going back down. 368 00:24:58,530 --> 00:25:04,500 Once we get the result from our task service Bindable invoke well, we can do is use the update UI event 369 00:25:04,500 --> 00:25:06,810 again and actually pass the outer frame. 370 00:25:06,810 --> 00:25:10,590 So this time we'll just basically copy what we've done here. 371 00:25:11,830 --> 00:25:16,300 Paste that down here to complete a task is going to be equal to the result. 372 00:25:16,300 --> 00:25:20,590 And instead, the message we can give them is that you escaped. 373 00:25:23,780 --> 00:25:29,630 And then for the info text, if you would like, you could continue on expanding the story in the future. 374 00:25:29,630 --> 00:25:35,270 So I've made this pretty easy where instead, when the players touch the escape part, you could teleport 375 00:25:35,270 --> 00:25:38,030 them to a new section in your story if you'd like. 376 00:25:38,030 --> 00:25:39,860 We're not going to be creating that new section. 377 00:25:39,860 --> 00:25:45,590 I think our story is good the way it is, but if you would like to expand that story or add a second 378 00:25:45,590 --> 00:25:52,280 section to the story, then you can give them some info text of like part two coming soon, whatever. 379 00:25:52,280 --> 00:25:56,360 Because, you know, there's a lot of horror games like Judy that have different chapters in the game 380 00:25:56,360 --> 00:26:00,320 that players could be able to play, and that's definitely something you could add into your horror 381 00:26:00,320 --> 00:26:01,790 game later in the future. 382 00:26:02,000 --> 00:26:08,180 Other than that, once we give them this information, we also want to award them a badge telling them 383 00:26:08,180 --> 00:26:11,000 that they successfully escaped from our basement. 384 00:26:11,000 --> 00:26:14,150 So that's where our badge handler is going to come into play. 385 00:26:14,150 --> 00:26:18,950 And that means we're going to have to create a custom badge for our game, so we can go ahead and open 386 00:26:18,950 --> 00:26:22,610 up our main story, and then we can go to file hit Game Settings. 387 00:26:22,610 --> 00:26:25,190 And then we can go to monetization. 388 00:26:28,280 --> 00:26:31,100 And inside of here is where we can create a new batch. 389 00:26:31,100 --> 00:26:32,750 So let's go ahead and create one. 390 00:26:33,200 --> 00:26:36,740 So now you should have this window opened up in your browser. 391 00:26:36,740 --> 00:26:39,350 You can give the name for your badge and the description. 392 00:26:39,350 --> 00:26:44,690 I'll just name this badge you escaped and say something like you successfully. 393 00:26:45,910 --> 00:26:55,510 Escaped the basement after being chased or after being trapped or whatever. 394 00:26:55,990 --> 00:27:00,220 We could do something like that, and then we can also upload an image for our badge as well, which 395 00:27:00,220 --> 00:27:01,540 I'll do real quick. 396 00:27:01,990 --> 00:27:05,350 So once you've uploaded your image, you've given a badge name and a description. 397 00:27:05,350 --> 00:27:07,030 You can go ahead and hit preview. 398 00:27:07,630 --> 00:27:11,020 Your image will show here, but since I just uploaded it, nothing is showing yet. 399 00:27:11,020 --> 00:27:14,830 And then after that you can go ahead and purchase it for zero Robux so it's free. 400 00:27:15,510 --> 00:27:20,310 After that, your badge has been successfully created and we can go back and hop into studio. 401 00:27:21,060 --> 00:27:24,660 And back inside of studio, we can go ahead and refresh our badges. 402 00:27:24,660 --> 00:27:27,060 And then here is our you escape the badge. 403 00:27:27,060 --> 00:27:31,770 We can hit the three dots here and copy the ID, because we're going to need that in a moment. 404 00:27:32,440 --> 00:27:37,210 But what we can do from this point is we can go ahead and start filling out our batch handler and our 405 00:27:37,210 --> 00:27:38,260 batch enum. 406 00:27:39,130 --> 00:27:44,710 So I'm going to go in here and again copy all of this, paste it inside of this enum. 407 00:27:45,040 --> 00:27:47,350 And then I'm going to delete all of this. 408 00:27:47,350 --> 00:27:49,390 And then windows has a neat feature. 409 00:27:49,390 --> 00:27:55,090 If you're on Windows 11 where you can hit down the windows key and then V and it'll show you your clipboard 410 00:27:55,090 --> 00:27:59,860 history where you can go ahead and grab your badge ID, but if you're not able to see your clipboard 411 00:27:59,860 --> 00:28:04,810 history, then it's easy for you to just go back into the game settings and grab that badge ID again. 412 00:28:04,810 --> 00:28:06,550 So in here we could create a key. 413 00:28:06,580 --> 00:28:08,320 We can call it Escaped Badge. 414 00:28:09,670 --> 00:28:16,210 And set it equal to the badge ID just like so, and then we can go ahead and start filling out our badge 415 00:28:16,210 --> 00:28:16,930 handler. 416 00:28:16,930 --> 00:28:20,710 So inside of this module script we're going to need the badge service. 417 00:28:20,710 --> 00:28:23,350 So game get service badge service. 418 00:28:24,050 --> 00:28:29,690 We'll create the table to represent this module script batch handler and return that at the end. 419 00:28:32,650 --> 00:28:38,350 And then we can also make a reference to our badge enum, and we'll require it from script dot badge 420 00:28:38,350 --> 00:28:39,010 enum. 421 00:28:39,820 --> 00:28:46,030 We'll again have the same function to check whether or not an ID is inside of our enum, so we can call 422 00:28:46,030 --> 00:28:51,610 it function is id an enum, and we will get past the badge id here. 423 00:28:53,150 --> 00:28:53,450 Again. 424 00:28:53,450 --> 00:28:54,800 We'll get our results. 425 00:28:55,520 --> 00:28:56,600 We'll set it to false. 426 00:28:56,600 --> 00:29:01,970 We'll loop through every single enum and value inside of our badge enum. 427 00:29:05,250 --> 00:29:11,910 And if the value is equal to the badge ID passed to this function, then we can go ahead and set result 428 00:29:11,910 --> 00:29:16,560 equal to true, and then return result at the very end of our function. 429 00:29:17,630 --> 00:29:21,860 And then inside of this handler we can have a function to award a badge. 430 00:29:21,860 --> 00:29:26,240 So badge handler award badge. 431 00:29:26,390 --> 00:29:30,080 We would pass the player we would like to award the badge to. 432 00:29:30,140 --> 00:29:32,450 And then we would pass the badge ID. 433 00:29:33,930 --> 00:29:36,930 We will check if this badge ID is inside of our enum. 434 00:29:36,930 --> 00:29:40,710 So if it is not, is id and enum, pass the badge ID. 435 00:29:43,090 --> 00:29:50,380 Then we can warn, give out a message and correct a badge ID given to award badge function. 436 00:29:51,420 --> 00:29:53,070 And then we'll just return. 437 00:29:53,070 --> 00:29:57,150 Otherwise, again we're going to use our p call function on the award badge function. 438 00:29:57,150 --> 00:30:01,020 So local success result is equal to p call. 439 00:30:01,780 --> 00:30:02,710 And we'll use badge. 440 00:30:02,710 --> 00:30:04,660 Service Award badge. 441 00:30:05,290 --> 00:30:10,360 Since this function also uses a colon, the first argument we need to pass is the badge service itself, 442 00:30:10,360 --> 00:30:14,080 and then we can pass the player user ID and then the badge ID. 443 00:30:16,290 --> 00:30:22,230 If we were not successful in awarding the badge, then we'll just put a warning and say something like 444 00:30:22,470 --> 00:30:25,770 unable to award badge. 445 00:30:26,130 --> 00:30:32,640 We'll pass the ID of the badge here to player, and we could pass the name of the player here. 446 00:30:33,410 --> 00:30:35,600 And then we can give out the error. 447 00:30:35,600 --> 00:30:39,530 So we'll put another directive and then we can go ahead and format this. 448 00:30:39,530 --> 00:30:44,840 The first thing we want to pass is the badge ID the second is the players name. 449 00:30:44,840 --> 00:30:47,780 And then lastly is the result from our p call. 450 00:30:47,780 --> 00:30:50,060 And that's all we need to do for our badge handler. 451 00:30:50,300 --> 00:30:57,050 So inside of our game service we can go back up and create a new variable for the badge handler. 452 00:30:57,050 --> 00:31:02,480 So local badge handler will require from server script service. 453 00:31:03,360 --> 00:31:04,170 Dot server. 454 00:31:04,170 --> 00:31:05,430 Dot modules. 455 00:31:05,430 --> 00:31:06,990 Dot batch handler. 456 00:31:07,810 --> 00:31:12,430 And then we're going to copy this and then get the badge enum. 457 00:31:13,450 --> 00:31:17,860 Match handler and get the badge enum again, and then we can go back down. 458 00:31:17,860 --> 00:31:22,990 And after we told the player that they have escaped, we can use our badge handler and award a badge 459 00:31:22,990 --> 00:31:24,070 to this player. 460 00:31:24,520 --> 00:31:28,900 And the badge ID is going to be from our badge enum, and we'll get the escaped badge. 461 00:31:29,170 --> 00:31:33,880 After this, we can use task dot delay to spawn a function after like five seconds. 462 00:31:33,880 --> 00:31:40,270 And the function we want to spawn is our teleport handler and we want to teleport a player two. 463 00:31:40,860 --> 00:31:45,870 The first thing of course we need to pass is the teleport handler itself to fulfill the self variable. 464 00:31:45,870 --> 00:31:47,880 Since this function uses a colon. 465 00:31:48,270 --> 00:31:53,220 Then we could pass a table containing the player, and then the place we want to teleport this player 466 00:31:53,220 --> 00:31:55,650 to is the place id enum dot lobby. 467 00:31:56,400 --> 00:32:00,270 After this, we want to check how many players have escaped in our game. 468 00:32:00,270 --> 00:32:01,830 So we'll create a number. 469 00:32:01,830 --> 00:32:05,790 We'll set it to zero, and then we can loop through every single player inside of the player service. 470 00:32:05,790 --> 00:32:07,080 Get players. 471 00:32:11,110 --> 00:32:14,950 And what we want to do is we want to check if this player is inside of our escaped players table. 472 00:32:14,950 --> 00:32:16,690 So we'll pass the player dot name. 473 00:32:16,990 --> 00:32:21,190 If they are inside of there, then we can go ahead and increment our number. 474 00:32:21,820 --> 00:32:28,960 And then after that, what we could do is we could check if our number is equal to the number of players 475 00:32:28,960 --> 00:32:29,920 and the player service. 476 00:32:29,920 --> 00:32:31,360 So get players. 477 00:32:32,660 --> 00:32:39,620 If it is, then we can basically have a variable where we can say all the players have escaped. 478 00:32:39,620 --> 00:32:46,430 And that way when this loop is happening up here, we can go ahead and stop the countdown from happening 479 00:32:46,430 --> 00:32:47,600 so we can go up. 480 00:32:47,600 --> 00:32:51,560 We can create a boolean, we'll call it all players escaped. 481 00:32:51,560 --> 00:32:53,360 We'll set it to false by default. 482 00:32:53,360 --> 00:32:55,490 Inside of this for loop we can check. 483 00:32:57,020 --> 00:33:01,370 If all the players escape, then we can use our update guy event, fire to all the clients and do the 484 00:33:01,370 --> 00:33:06,620 guy actions in the update countdown and set the number equal to zero. 485 00:33:06,620 --> 00:33:11,780 That way the countdown stops for all the players, and then we can just go ahead and return out of this 486 00:33:11,780 --> 00:33:16,310 function entirely, because we do not need to teleport any losing players back to the lobby, considering 487 00:33:16,310 --> 00:33:18,170 all of the players have escaped. 488 00:33:18,170 --> 00:33:22,970 And another important thing we need to ensure that we do in here is we actually yield for one second. 489 00:33:22,970 --> 00:33:26,030 That way we're actually counting down for a total of 60s. 490 00:33:26,330 --> 00:33:26,750 All right. 491 00:33:26,750 --> 00:33:28,550 We got a lot of good work done in this lecture. 492 00:33:28,550 --> 00:33:34,610 So now it's time for us to go ahead and test out whether or not we can escape from the basement so we 493 00:33:34,610 --> 00:33:36,830 can go ahead and play test our story. 494 00:33:36,830 --> 00:33:40,310 And when we get to the basement section, I'll go ahead and meet you there. 495 00:33:40,760 --> 00:33:41,420 Okay. 496 00:33:41,420 --> 00:33:46,310 Now we are inside of our basement, and what I'm going to do is I'm going to locate where the key giver 497 00:33:46,310 --> 00:33:47,510 is for our breaker door. 498 00:33:47,510 --> 00:33:51,620 So inside of the Krusty Krab basement, we're going to find the breaker room key giver. 499 00:33:51,620 --> 00:33:53,240 So it's highlighted for us on the map. 500 00:33:53,240 --> 00:33:56,210 And we can go ahead and try to find it, which it is over here. 501 00:33:58,590 --> 00:34:02,640 So we're going to go ahead and grab this and head over to the door. 502 00:34:03,900 --> 00:34:09,180 And when we open and unlock the door, that means the prompt that is inside of the breaker box in there 503 00:34:09,180 --> 00:34:10,050 should be enabled. 504 00:34:10,050 --> 00:34:12,330 So let's go ahead and test to see what happens. 505 00:34:12,330 --> 00:34:16,290 We open that, there's our breaker panel and there should be a prompt. 506 00:34:16,290 --> 00:34:16,920 Perfect. 507 00:34:16,920 --> 00:34:18,120 We have an interact prompt. 508 00:34:18,120 --> 00:34:19,350 If we hold down E. 509 00:34:19,650 --> 00:34:23,310 Once we've triggered the prompt the light should turn back on. 510 00:34:23,310 --> 00:34:27,990 We should get a countdown started and our skate music should start playing at the same time. 511 00:34:27,990 --> 00:34:32,640 Our escape door should be opening and we should be able to touch the escape part. 512 00:34:32,640 --> 00:34:34,080 So let's go ahead and see what happens. 513 00:34:35,910 --> 00:34:39,900 So we hold down E, we hold down E and it eventually should trigger. 514 00:34:40,740 --> 00:34:41,460 There we go. 515 00:34:41,640 --> 00:34:43,950 We are told to escape the basement. 516 00:34:43,950 --> 00:34:45,510 We have a countdown going. 517 00:34:46,020 --> 00:34:48,930 As you can hear, our alarm is playing on the door. 518 00:34:49,470 --> 00:34:52,920 So let's go ahead and run and hurry up before this timer reaches zero. 519 00:34:55,970 --> 00:34:56,690 So we're running. 520 00:34:56,690 --> 00:34:59,960 We're running trying to find the exit to the basement. 521 00:35:05,800 --> 00:35:06,400 And there we go. 522 00:35:06,430 --> 00:35:07,960 As you can see, our door is open. 523 00:35:07,990 --> 00:35:12,640 The light is green, and there is this nice surface light projecting out of the part that is in this 524 00:35:12,640 --> 00:35:13,090 door. 525 00:35:13,090 --> 00:35:18,730 And if we go and touch it, we should get a thing displayed on our screen showing us what exactly we 526 00:35:18,730 --> 00:35:19,510 completed. 527 00:35:19,540 --> 00:35:22,660 Currently, I completed no tasks and I didn't get any money. 528 00:35:22,900 --> 00:35:25,030 Should tell me zero and zero. 529 00:35:25,030 --> 00:35:26,800 So let's go ahead and touch it and see what happens. 530 00:35:27,640 --> 00:35:32,050 We did get our escape badge, which is great, but unfortunately we did get an error which was unable 531 00:35:32,050 --> 00:35:35,620 to assign a property to text string. 532 00:35:35,620 --> 00:35:41,200 Expected God to know our teleport system did work because we can't teleport in studio. 533 00:35:41,200 --> 00:35:45,130 But let's go ahead and see what our problem is here. 534 00:35:47,080 --> 00:35:51,880 So first off, in the main guy handler we have argument one missing or nil. 535 00:35:51,880 --> 00:35:54,070 So that's on line 154. 536 00:35:58,010 --> 00:36:04,040 So inside of our main guy handler on line 154 the fulfilled objective when we get. 537 00:36:05,110 --> 00:36:06,610 This here. 538 00:36:06,610 --> 00:36:11,440 Apparently the fulfilled objective name is probably nil again. 539 00:36:11,440 --> 00:36:14,020 So if we go back to our game service. 540 00:36:14,790 --> 00:36:15,450 And find out. 541 00:36:15,450 --> 00:36:20,850 When we tell the player that they fulfilled an objective, perhaps we spelled something wrong. 542 00:36:20,850 --> 00:36:21,840 And we did. 543 00:36:21,840 --> 00:36:26,220 We did fulfilled object name instead of filled, fulfilled, objective name. 544 00:36:26,220 --> 00:36:27,960 So we got to fix that. 545 00:36:27,960 --> 00:36:32,520 And then the second area we had was on line 206 in our main guy handler. 546 00:36:32,520 --> 00:36:34,020 So we'll scroll down to that. 547 00:36:35,450 --> 00:36:39,650 And apparently args.info text is nil. 548 00:36:39,650 --> 00:36:45,710 So that means when we get past information text I'll go ahead and look for that in here. 549 00:36:45,710 --> 00:36:46,940 Info text. 550 00:36:46,940 --> 00:36:51,710 Apparently this is nil and we pass it to the player, which is actually kind of interesting. 551 00:36:54,240 --> 00:36:59,730 Because we pass the info text here and we also pass the info text here as well. 552 00:36:59,730 --> 00:37:03,360 But it says we got nil. 553 00:37:04,460 --> 00:37:10,460 Oh, and it looks like the problem is, for some reason, inside of here, we're passing. 554 00:37:11,420 --> 00:37:13,280 A table with the player inside of it. 555 00:37:13,280 --> 00:37:17,090 I have no idea why we're doing that inside of our Fhir client function. 556 00:37:17,090 --> 00:37:19,400 Let's go ahead and get rid of that. 557 00:37:19,400 --> 00:37:24,350 And then inside of the other info text section where for some reason doing the exact same thing. 558 00:37:24,350 --> 00:37:25,790 So I'm going to delete that as well. 559 00:37:25,790 --> 00:37:27,620 I'm not sure why that is in there. 560 00:37:29,160 --> 00:37:32,160 But let me just double check that everything looks okay. 561 00:37:32,160 --> 00:37:38,070 We get the money, we have the title text, we have the info text, and then we have the completed tasks. 562 00:37:38,070 --> 00:37:39,240 Okay, that looks good. 563 00:37:39,240 --> 00:37:40,980 We go to the other info text. 564 00:37:40,980 --> 00:37:47,280 We have our money, the title text, the info text and then the completed tasks as well. 565 00:37:47,280 --> 00:37:48,600 So that looks good. 566 00:37:49,110 --> 00:37:53,880 Apparently we just had a minor syntactical error in our script, but other than that I think everything 567 00:37:53,880 --> 00:37:55,260 should be working good now. 568 00:37:55,260 --> 00:37:57,420 So let's go ahead and test out our game again. 569 00:37:59,190 --> 00:37:59,520 All right. 570 00:37:59,520 --> 00:38:01,560 We're almost done restoring the power here. 571 00:38:01,560 --> 00:38:02,970 And there we go. 572 00:38:03,150 --> 00:38:04,680 Our timer has started. 573 00:38:04,680 --> 00:38:07,140 Let's go ahead and run over to the exit. 574 00:38:07,140 --> 00:38:09,960 And let's see if we get any different errors. 575 00:38:09,960 --> 00:38:12,510 This time when we try to teleport ourselves back. 576 00:38:12,600 --> 00:38:14,610 So to run, we'll run. 577 00:38:16,980 --> 00:38:20,580 Eventually we'll get there, make sure I'm. 578 00:38:20,580 --> 00:38:21,690 I'm even getting lost. 579 00:38:21,690 --> 00:38:22,740 But, uh, here it is. 580 00:38:22,740 --> 00:38:23,280 Okay. 581 00:38:24,930 --> 00:38:27,960 We run all the way to the exit. 582 00:38:29,220 --> 00:38:33,690 And now when we touch this, we should get that guy showing up on our screen telling us what we got 583 00:38:33,720 --> 00:38:35,820 done, and then we should get teleported back. 584 00:38:35,820 --> 00:38:36,600 So we touch it. 585 00:38:36,600 --> 00:38:37,260 There we go. 586 00:38:37,260 --> 00:38:37,950 You escaped. 587 00:38:38,370 --> 00:38:38,760 Part two. 588 00:38:38,760 --> 00:38:39,210 Coming soon. 589 00:38:39,210 --> 00:38:43,230 You have $0 and zero tasks completed, teleporting you back to the lobby. 590 00:38:43,230 --> 00:38:48,660 And of course it's not working because we're in studio, but that means that it should be working when 591 00:38:48,660 --> 00:38:50,610 we actually publish this game to Roblox. 592 00:38:50,610 --> 00:38:55,680 So now the next thing I actually want to test is what happens if we don't reach that escape part in 593 00:38:55,680 --> 00:38:56,400 time. 594 00:38:58,230 --> 00:39:00,870 And look, we also got our teleport timed out as well. 595 00:39:07,150 --> 00:39:07,720 Okay. 596 00:39:07,720 --> 00:39:11,890 And this time I'm going to just sit here and let the timer reach zero. 597 00:39:11,890 --> 00:39:18,040 And I want to see if we get the outro frame displayed on our screen where it tells us you failed, and 598 00:39:18,040 --> 00:39:20,230 then we get teleported back to the lobby. 599 00:39:20,230 --> 00:39:23,920 So let's go ahead and wait for this timer to run out and see what happens. 600 00:39:24,520 --> 00:39:26,980 All right, our timer is almost over. 601 00:39:26,980 --> 00:39:29,260 Three, two, one. 602 00:39:29,260 --> 00:39:30,790 Let's see what happens. 603 00:39:30,820 --> 00:39:33,640 Timers up and we did get an error. 604 00:39:33,640 --> 00:39:35,560 So let's see what happened. 605 00:39:35,560 --> 00:39:37,750 Attempt to index nil with number. 606 00:39:37,750 --> 00:39:42,340 So we got attempt to index nil with number at the same spot twice. 607 00:39:42,520 --> 00:39:45,340 So this was inside of our task service. 608 00:39:45,340 --> 00:39:47,080 Let's go ahead and see what happened. 609 00:39:48,580 --> 00:39:54,400 So on line 220 inside of the task service we're getting an error attempt to index nil with number. 610 00:39:54,400 --> 00:39:56,140 And that's going to be right here. 611 00:39:56,140 --> 00:39:58,450 So apparently args is nil. 612 00:39:58,450 --> 00:40:00,430 And when we index it with one it doesn't like it. 613 00:40:00,430 --> 00:40:04,360 And it's telling us we're attempting to index this which is nil with a number. 614 00:40:04,360 --> 00:40:05,800 Why would that be a number. 615 00:40:05,800 --> 00:40:10,360 Well it might be explained from our game service on line 77. 616 00:40:10,360 --> 00:40:11,890 So let's go to that. 617 00:40:12,430 --> 00:40:17,530 And inside of here when we use our task service Bindable and get the completed task for a player, it 618 00:40:17,530 --> 00:40:25,330 looks like we actually forgot to actually pass the player in a table to our invoke function. 619 00:40:25,330 --> 00:40:28,060 So that's exactly why it didn't work. 620 00:40:28,060 --> 00:40:33,880 But now that we fixed that, let's go ahead and test this out one last time to see if it works or not. 621 00:40:36,050 --> 00:40:36,530 Okay. 622 00:40:36,530 --> 00:40:37,910 Our timer is almost up. 623 00:40:37,910 --> 00:40:41,450 Let's go ahead and see what happens when we don't reach the exit door in time. 624 00:40:41,660 --> 00:40:42,440 Got three. 625 00:40:42,440 --> 00:40:44,600 Two, one. 626 00:40:44,990 --> 00:40:46,310 Hopefully no errors. 627 00:40:46,400 --> 00:40:47,120 There we go. 628 00:40:47,120 --> 00:40:47,750 You failed. 629 00:40:47,750 --> 00:40:49,220 Unfortunately, you failed to win this time. 630 00:40:49,220 --> 00:40:49,880 Don't give up. 631 00:40:49,880 --> 00:40:53,810 Try again and we should get teleported back to the lobby any second now. 632 00:40:54,410 --> 00:40:56,060 At any second. 633 00:40:56,420 --> 00:40:56,990 There we go. 634 00:40:56,990 --> 00:41:02,150 Teleport fail due to an unexpected error because we can't teleport while we're in studio. 635 00:41:02,150 --> 00:41:05,330 But it looks like everything we've scripted is working great. 636 00:41:07,460 --> 00:41:11,270 And our teleport timed out as well, so that's also good to see. 637 00:41:12,220 --> 00:41:17,590 So far everything is working well in our game and in the next lecture, I think it's time to get started 638 00:41:17,590 --> 00:41:19,240 with scripting our AI. 639 00:41:19,270 --> 00:41:19,990 Squidward. 640 00:41:20,230 --> 00:41:21,880 I will see you there.